#!/usr/bin/env python
# -*- coding: utf-8 -*-
#===============================================================================
# Copyright 2011 zod.yslin
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# 
# Author: zod.yslin
# Email: 
# File Name: destructor.py
# Description: 
#   建構子 (constructor) 用來建立物件 (object) ，當物件不需要被使用時，
#   直譯器 (interpreter) 會主動替物件呼叫 __del__() 方法 (method) ，
#   這是物件自動銷毀的方法，也就是從記憶體中釋放空間的步驟，
#   被稱為解構子 (destructor) ，當然，我們也可以改寫 (override) 這個方法。
# Edit History: 
#   2011-08-12    File created.
#===============================================================================
class Demo:
    def __init__(self, i):
        self.i = i
     
    def __str__(self):
        return str(self.i)
     
    def __del__(self):
        print("bye-bye " + self.__str__())
          
    def hello(self):
        print("hello " + self.__str__())
 
a = Demo(22)
a.hello()
a = Demo(33)
a.hello()
a = Demo(44)
a.hello()
a = Demo(55)
a.hello()
